package framework.web;

import framework.service.impl.UserServiceImp;
import framework.pojo.User;
import framework.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {

    private UserService userService = new UserServiceImp();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        User Luer = userService.login(new User(null,username,password,null));
        //如果Luer为空，则表示登录不成功
        if (Luer==null){
            req.setAttribute("alertMsg","用户名或密码错误");
            req.getRequestDispatcher("/page/user/login.jsp").forward(req,resp);
        }
        else{
            req.getRequestDispatcher("/page/user/loginSuccess.jsp").forward(req,resp);
        }
    }
}
